/*
 * SoundManager.cpp
 *
 *  Created on: 01/06/2014
 *      Author: javier
 */

#include "SoundManager.h"

SoundManager::SoundManager() {
	bomb_explosion = Mix_LoadWAV("sound/bomb_explosion.wav");
	bomberman_destroy = Mix_LoadWAV("sound/bomberman_destroy.wav");
	zombie_destroy = Mix_LoadWAV("sound/zombie_destroy.wav");
	bomb_planted = Mix_LoadWAV("sound/bomb_planted.wav");
	bomb_throw = Mix_LoadWAV("sound/bomb_throw.wav");
}

SoundManager::~SoundManager() {
	Mix_FreeChunk(bomb_explosion);
	Mix_FreeChunk(bomberman_destroy);
	Mix_FreeChunk(zombie_destroy);
	Mix_FreeChunk(bomb_planted);
	Mix_FreeChunk(bomb_throw);
	Mix_Quit();
}

void SoundManager::playEvent(Positionable* p, SoundEvent event) {
	if (event == NEW_OBJECT) {
		if (p->getModelObjectType() == BOMB) {
			Mix_PlayChannel(-1, bomb_planted, 0);
		}
//		Mix_PlayChannel(-1, bomb_throw, 0);
	} else if (event == DESTROY_OBJECT) {
		if (p->getModelObjectType() == BOMB) {
			Mix_PlayChannel(-1, bomb_explosion, 0);
		} else if (p->getModelObjectType() == ZOMBIE_BLUE) {
			Mix_PlayChannel(-1, zombie_destroy, 0);
		} else if (p->getModelObjectType() == ZOMBIE_RED) {
			Mix_PlayChannel(-1, zombie_destroy, 0);
		} else if (p->getModelObjectType() == ZOMBIE_GREEN) {
			Mix_PlayChannel(-1, zombie_destroy, 0);
		} else if (p->getModelObjectType() == BOMBERMAN_WHITE) {
			Mix_PlayChannel(-1, bomberman_destroy, 0);
		} else if (p->getModelObjectType() == BOMBERMAN_BLACK) {
			Mix_PlayChannel(-1, bomberman_destroy, 0);
		} else if (p->getModelObjectType() == BOMBERMAN_RED) {
			Mix_PlayChannel(-1, bomberman_destroy, 0);
		} else if (p->getModelObjectType() == BOMBERMAN_PURPLE) {
			Mix_PlayChannel(-1, bomberman_destroy, 0);
		} else if (p->getModelObjectType() == BOMBERMAN_GREEN) {
			Mix_PlayChannel(-1, bomberman_destroy, 0);
		} else if (p->getModelObjectType() == BOMBERMAN_YELLOW) {
			Mix_PlayChannel(-1, bomberman_destroy, 0);
		}
	}
}
